package com.ewzj.bigdata.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.ewzj.bigdata.app.constants.AppConstants;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.ewzj.bigdata.di.component.DaggerLogoComponent;
import com.ewzj.bigdata.di.module.LogoModule;
import com.ewzj.bigdata.mvp.contract.LogoContract;
import com.ewzj.bigdata.mvp.presenter.LogoPresenter;

import com.ewzj.bigdata.R;
import com.jess.arms.utils.DataHelper;
import com.tbruyelle.rxpermissions2.RxPermissions;


import javax.inject.Inject;

import butterknife.BindView;
import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author zhangjing
 * 启动页面，主要用于广告logo的展示
 */
public class LogoActivity extends BaseActivity<LogoPresenter> implements LogoContract.View {

    @BindView(R.id.logo_img)
    ImageView logo_img;
    @Inject
    RxPermissions mRxPermissions;
    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerLogoComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .logoModule(new LogoModule(this))
                .build()
                .inject(this);
    }

    @Override
    public boolean useFragment() {
        return false;
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.activity_logo;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mPresenter.initBaiduconfig();
        mPresenter.requestPermissons();
//         showAdvert();
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public void showAdvert() {
        //渐变展示启动屏
//        AlphaAnimation   alpha = new AlphaAnimation(1.0f, 0.0f);
//        alpha.setDuration(4000);
//        alpha.setFillAfter(true);
//        logo_img.setAnimation(alpha);
        //渐变展示启动屏
        AlphaAnimation aa = new AlphaAnimation(0.1f,1.0f);
        aa.setDuration(3000);
        logo_img.startAnimation(aa);
        aa.setAnimationListener(new Animation.AnimationListener()
        {
            @Override
            public void onAnimationEnd(Animation arg0) {
                nextActivity();
            }
            @Override
            public void onAnimationRepeat(Animation animation) {}
            @Override
            public void onAnimationStart(Animation animation) {}

        });

    }

    @Override
    public void nextActivity() {
        if (TextUtils.isEmpty(DataHelper.getStringSF(this, AppConstants.IS_SHOW_SPLASH)))
        {
            DataHelper.setStringSF(this, AppConstants.IS_SHOW_SPLASH,AppConstants.IS_SHOW_SPLASH);
            ArmsUtils.startActivity(SplashActivity.class);
        }else {
            ArmsUtils.startActivity(MainTabActivity.class);
            killMyself();
        }
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    public RxPermissions getmRxPermissions() {
        return mRxPermissions;
    }
}
